<?php
require_once('../../includes/classes/core.php');

//----------------------------- ცვლადი

$agent	= $_REQUEST['agent'];
$queue	= $_REQUEST['queuet'];
$start_time = $_REQUEST['start_time'];
$end_time 	= $_REQUEST['end_time'];
$day = (strtotime($end_time)) -  (strtotime($start_time));
$day_format = ($day / (60*60*24)) + 1;


// ----------------------------------

if($_REQUEST['act'] =='check'){

		
//--------------------------- ნაპასუხები ზარები ოპერატორების მიხედვით

 	$ress =mysql_query("
 	                    SELECT	CASE
									WHEN dst_extension = 'ALF2' THEN 'მამუკა'
									WHEN dst_extension = 'ALF3' THEN 'ნინო'
									WHEN dst_extension = 'ALF4' THEN 'თამო'
									WHEN dst_extension = 'ALF5' THEN 'ლაშა'
									WHEN dst_extension = 'ALF6' THEN 'სალომე მიროტაძე'
									WHEN dst_extension = 'ALF7' THEN 'მარი კუპატაძე'
									WHEN dst_extension = 'ALF8' THEN 'ნინო ტოხიშვილი'
									WHEN dst_extension = 'ALF9' THEN 'რუსუდან ბოჭორიშვილი'
							    END AS `op_name`,
                                COUNT(*) AS `count`,
                                ROUND(((COUNT(*) / (SELECT  COUNT(*) AS `count`
                            						FROM 	asterisk_incomming
                                                    WHERE 	disconnect_cause != 'ABANDON'
                                                    AND 	DATE(datetime) >= '$start_time'
                                                    AND 	DATE(datetime) <= '$end_time'
                                                    AND 	dst_queue IN ($queue)
                                                    AND		dst_extension IN ($agent)
                                )) * 100),2) AS `count_pr`,
                                SEC_TO_TIME(SUM(duration)) AS `duration`,
                                SEC_TO_TIME(SUM(duration)/COUNT(*)) AS `abs`
						FROM 	asterisk_incomming
                        WHERE 	disconnect_cause != 'ABANDON'
                        AND 	DATE(datetime) >= '$start_time'
                        AND 	DATE(datetime) <= '$end_time'
                        AND 	dst_queue IN ($queue)
                        AND		dst_extension IN ($agent)
						GROUP BY dst_extension
 	                  ");

while($row = mysql_fetch_assoc($ress)){

	$data['page']['answer_call_by_queue'] .= '

                   	<tr>
					<td style="cursor:pointer;" id="name">'.$row[op_name].'</td>
					<td>'.$row[count].'</td>
					<td>'.$row[count_pr].' %</td>
					<td>'.$row[duration].' წამი</td>
					<td>'.$row[abs].' წუთი</td>
					</tr>

							';

}

echo json_encode($data);
}
?>